/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
char* replaceSpaces(char *str){
    int cntSpace = 0, cntChar = 0;
    for (int i = 0; i < 1000; i++){
        if (str[i] != '\0'){
            if (str[i] == ' ')
                cntSpace++;
            else 
                cntChar++;
        } else {
            i = 999;
            break;
        }
    }
    
    char *newStr = (char*)malloc((cntChar + 3*cntSpace) * sizeof(char));
    int j = 0;
    for (int i = 0; i < cntSpace + cntChar; i++){
        if (str[i] == ' '){
            newStr[j++] = '%';
            newStr[j++] = '2';
            newStr[j++] = '0';
        } else 
            newStr[j++] = str[i];
    }
    return newStr;
}